﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "CreateDim", "1.0")]
    public class CreateDimAction : BaseAction<CreateDimParams, CreateDimResult>
    {
        protected override ActionResult<CreateDimResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            CreateDimParams opParams)
        {
            SER.DimService service = new SER.DimService();
            ServiceResult<ENT.EDim> serResult = service.CreateDim(context.UserId, opParams.Code, opParams.Name);
            if(serResult.IsSuccess)
            {
                CreateDimResult result = new CreateDimResult();
                result.Id = serResult.Data.Id;
                return new ActionResult<CreateDimResult>(result);
            }
            else
            {
                return new ActionResult<CreateDimResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class CreateDimParams
    {
        [Parameter]
        public string Name { get; set; }

        [Parameter]
        public string Code { get; set; }
    }

    public class CreateDimResult
    {
        public Guid Id { get; set; }
    }
}
